package view.gift
{
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.events.Event;
	
	import global.Resource;
	
	import utils.DisplayTool;
	import utils.animate.AlphaMoveTween;
	
	public class Gift extends Sprite
	{
		private var title:Bitmap;
		private var bg:Bitmap;
		private var type:String;
		private var tween:AlphaMoveTween;
		
		public function Gift(type:String)
		{
			this.type = type;
			this.mouseChildren = false;
			this.mouseEnabled  = false;
			initBg();
			initTitle();
			initTween();
		}
		
		private function initTween():void
		{
			tween = new AlphaMoveTween();
			tween.addEventListener(Event.COMPLETE,onTweenComplete);
		}
		
		private function onTweenComplete(event:Event):void
		{
			destroy();
			
		}
		
		public function send(fx:Number,fy:Number,tx:Number,ty:Number):void
		{
			tween.setTarget(this,fx,fy,tx,ty);
			tween.start();
		}
		
		private function initBg():void
		{
			if (type == "0")
			{
				bg = Resource.getImg("face_golds");
			}
			else
			{
				bg = Resource.getImg("panel_item_" + type);
			}
			addChild(bg);
		}
		
		private function initTitle():void
		{
			title = Resource.getImgXY(20,-2,"panel_give"); 
			addChild(title);
		}
		
		public function destroy():void
		{
			DisplayTool.removeChild(this.parent,this);
			DisplayTool.removeAllChild(this);
			bg.bitmapData = null;
			title.bitmapData = null;
			bg = null;
			title  = null;
			tween.removeEventListener(Event.COMPLETE,onTweenComplete);
			tween.destroy();
			tween = null;
		}
	}
}